figure = plt.figure(figsize=(8,8))
# ax = figure.add_subplot(111, projection='3d')
ax = figure.add_subplot(111)  # 修改成二维平面
xy = np.linspace(-0.5, 1.5, 51)
x_grid, y_grid  = np.meshgrid(xy, xy) # (51,51)
xy_grid = np.stack([x_grid, y_grid], axis=-1) # (51,51,2)
z_xor = xor_model(xy_grid)
z_xor = z_xor.squeeze()
# 绘制拟合曲面的等高线
ax.contour(x_grid, y_grid, z_xor, 1, offset=0.0, colors='black')
# 绘制样本数据点在X,Y平面的投影
x1 = np.array([0, 1])
y1 = np.array([0, 1])
x2 = np.array([0, 1])
y2 = np.array([1, 0])
ax.scatter(x1, y1, c='b', s=80, marker="^") # ”^"表示三角形
ax.scatter(x2, y2, c='b', s=80, marker="+") # "+"表示+图形
ax.set_xticks([0, 1])
ax.set_xlabel('X')
ax.set_yticks([0, 1])
ax.set_ylabel('Y')
# ax.set_zticks([0, 1])
# ax.set_zlabel('Z')
plt.show()
